Overview

  1. what is an operating system, and what's its role it plays in a computer system
  2. what are key components of an operations sytem
  3. Design and implementation considerations of operation system

Simple OS Definition

A special piece of software that abstacts and arbitrates the underlying hardware of a computer system.

  1. Abstract: simplify the hardware system
  2. arbitrate: to manage, to oversee, or to control the hardware system

Operating System

  1. Direct operational resources: control use of CPU, memory, peripheral devices ...
  2. Enforce working policies: fair resource access, limits to resource usage
  3. Mitigate difficulty of complex task: abstract hardware details (system calls)

What's an OS and its role

  1. A layer of system software sits between complex hardware and applications
  2. hide hardware complexity
  3. resource management
    1. manage memory
    2. scheulde CPU
    3. control access to the devices
  4. provide isolation & protection (allocate different section of memory to different application and ensure they don't access others' data)

OS Definition

OS is a layer of systems software that

  1. directly has primileged access to the underlying hardware
  2. hides the hardware complexity
  3. manage hardware on behalf of one of more applications according to some predicted policies
  4. in addition, it ensures that applications are isolated and protected from one antoher.

image.png OS doesn't manage cache memory, hardware does

image.png

OS Examples

  1. MS Windows
  2. UNIX-based 1.Mac OSX (BSD)
    1. LINUX
  3. Android
  4. iOS
  5. Symbian

OS Elements

  1. Abstractions
    1. process
    2. thread
    3. file
    4. socket
    5. memory
    6. page
  2. Mechanisms
    1. create
    2. schedule
    3. open
    4. write
    5. allocate
  3. policies
    1. least-recently used (LRU)
    2. earliest deadline first (EDF)

OS Elements: memory management example

  1. Abstractions: memory page, corresponsible to a addreeable region of memory of fixed size.
  2. Mechanism:
    1. allocate: allocate the page in DRAM
    2. map: map it into the address space of a process, then the process can access the physical memory correspondent to the content of that page.
    3. the page may move to different locations of the memory or even be stored on disk
  3. Policies:
    1. least reently used (LRU): swap the page in memory to disk

Design Principles

  1. Sepearation of mechanism & policy: implement flexible mechanism to support many policies (LRU, LFU, random, etc.)
  2. Optimize for common case
    1. where will the OS be used (what kind of machine, processing elements: how many cpu, how much memory, what devices)
    2. what will the user want to execute on that machine? (what's the applciation)
    3. what are the workload requirements

User/Kernel Protection Boundary

  1. Privileged mode/Kernel-level: OS kernel has privileged direct hardware access
  2. Unprivileged mode/User level: applciation
  3. User-kernel swith is supported by hardware: trap
    1. privilege bit on CPU: if not set, attempt to perform privilege opeation will be forbiden. This will cause a trap
    2. Trap instructions: the application will be interrupted and the hardware will switch control to OS. Then the OS can check what cause the trap occur, then decide if it should grant the access or terminate the process.
  4. System call:
    1. interface of interaction between OS and application
    2. OS export system call interface
    3. Applications can invoke if they want the OS to perform certain service or privilage access on their behave.
      1. open(file)
      2. send(socket)
      3. malloc(memory)
  5. signals:
    1. OS passes information to the application

image-2.png

Switch execution context between user-mode and kernel mode, not a cheap operation

To make a system call, an applciation must

  1. write arguments: can be directly passed to the program or through address
  2. save relevant data at well-defined location
  3. make system call: a system call number, also decide how many arguments to retrive
  4. Synchronous mode: process will wait until the system call completes

Crossing the User/Kernel Protection Boundary

User/kernel transitions: neccessary steps during applciation execution

  1. hardware supported: traps on illegal instructions or memory accesses requiring special privilege
  2. Involves a number of instruction: 50-100ns on a 2GHz machien running Linux for the transition
  3. Switches locality: affects hardware cache (can be hundreds faster than memory)
  4. Not cheap

Basic OS Services

  1. scheduler: controll access to the CPUs
  2. memory manager:
    1. allocate physical memory to one or more applications
    2. make sure multi applications don't overwrite each other's memory
  3. block device driver: access to block devices like disk
  4. file system
  5. process management
  6. file management
  7. device management
  8. memory management
  9. storage management
  10. security
  11. ...

Windows vs Linux System Calls

image.png

image.png

Monolithic OS

  1. Every possible service that every application can require or any type of hardware can demand is already part of the OS
  2. It may include different types of file systems for random I/O and sequential access etc
  3. This can make OS potentially really large

Pros

  1. Everything included
  2. inlining, compile-time optimization

Cons:

  1. coustomization, portability, manageability
  2. memory footprint
  3. performance

Modular OS

  1. has a number of basic services as API
  2. everything can be added as a module
  3. OS specifies some module interface, which any module must impliment in order to be part of the OS

Pros:

  1. maintaianability
  2. smaller footprint
  3. less resource needs

Cons:

  1. due to the specified interface, indirection can impact performance
  2. maintianance can still be an issue because the codes are from different sources.

Microkernel

  1. require only the basic primitive at the OS level
  2. everything else run outside the OS at the user level

Pros:

  1. size
  2. verifiability
  3. good for embeded or control system

Cons

  1. portability: customized for the underlying hardware
  2. complexity of software development
  3. cost of user/kernel crossing

Linux Architecture

image.png

image-2.png

Each component can be individually modified or replaced.

Mac OS Architecture

image.png

In [ ]: